<% layout('/layouts/default.html', {title: '到单押汇管理', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(billNegotiated.isNewRecord ? '新增到单押汇' : '编辑到单押汇')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${billNegotiated}" action="${ctx}/financial/billnegotiated/billNegotiated/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('车辆信息')}</div>
				<#form:hidden path="billNegotiatedId"/>
				<#form:hidden path="ladingBillId"/>
				<#form:hidden path="tentativeExchangeRate"/>
				<#form:hidden path="investorInterestRatio"/>
				<#form:hidden path="customerInterestRatio"/>
				<#form:hidden path="investorYearDays"/>
				<#form:hidden path="carId"/>
				<#form:hidden path="rowNumber"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('车架号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="frameNumber" items="${frameNumberList}" onchange="frameNumberChange()"
								itemLabel="frameNumber" itemValue="frameNumber" blankOption="true" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('品牌')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="brandName" dictType="car_pinpai" blankOption="true" class="form-control" readonly="true"/>
								<#form:hidden path="brand"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('版型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="areaName" dictType="car_quyu" blankOption="true" class="form-control" readonly="true"/>
								<#form:hidden path="area"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('车型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="model" maxlength="100" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('价格（原币种）')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="unitPrice" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('币种')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="currency" dictType="sys_bizhong" blankOption="true" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('状态')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="status1" dictType="bill_negotiated_status" blankOption="true" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('押汇主体信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="billNegotiatedCode" maxlength="100" class="form-control" placeholder="自动生成" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('信用证')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="letterCreditCode" items="${listLetterCredit}"
								itemLabel="letterCreditCode" itemValue="letterCreditId" blankOption="true" class="form-control " readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('服务订单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="serviceOrderCode" items="${listServiceOrder}"
								itemLabel="serviceOrderCode" itemValue="serviceOrderId" blankOption="true" class="form-control required" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('委托协议')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="entrustAgreement" maxlength="100" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客户')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:treeselect id="customer" title="${text('客户选择')}"
								path="customer.customerId" labelPath="customer.customerName"
								url="${ctx}/base/customer/customer/treeData" canSelectRoot="true" canSelectParent="true"
								class="" allowClear="true"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('国内资方')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="investorId" items="${gnzfList}" itemLabel="supplierName" itemValue="supplierId"
								class="form-control required" blankOption="true" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('资方押汇方案')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="investorNegotiatedPlan" itemLabel="name" itemValue="id"
								class="form-control" blankOption="true" onchange="n1FlagChange()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('外贸合同号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="foreignTradeContractNumber" maxlength="100" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('保证金购汇汇率')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="marginPurchaseExchangeRate" maxlength="10" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('押汇比例(%)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="negotiatedRatio" maxlength="10" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('押汇金额')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="negotiatedAmount" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('押汇信息-资方')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('是否N+1')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="n1Flag" dictType="sys_yes_no" blankOption="true" class="form-control" onchange="n1FlagChange()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('开始日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="startDate" readonly="true" maxlength="20" class="form-control laydate required"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="startDateChange()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('资方结束日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorEndDate" readonly="true" maxlength="20" class="form-control laydate required"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="checkInvEndDate()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('客户结束日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerEndDate" readonly="true" maxlength="20" class="form-control laydate required"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="checkCusEndDate()"/>
							</div>
						</div>
					</div>
				</div>
				<div class="ml10 mr10">
					<table id="billNegotiatedDetailDataGrid1"></table>
<!--					<% if (hasPermi('financial:billnegotiated:billNegotiated:edit')){ %>-->
<!--					<a href="#" id="billNegotiatedDetailDataGridAddRowBtn1" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>-->
<!--					<% } %>-->
				</div>
				<div class="form-unit">${text('押汇信息-客户')}</div>
				<div class="ml10 mr10">
					<table id="billNegotiatedDetailDataGrid2"></table>
<!--					<% if (hasPermi('financial:billnegotiated:billNegotiated:edit')){ %>-->
<!--					<a href="#" id="billNegotiatedDetailDataGridAddRowBtn2" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>-->
<!--					<% } %>-->
				</div>
				<div class="form-unit">${text('计算')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('押汇本金（RMB）')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="negotiatedAmountRmb" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('资方押汇利息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorNegotiatedInterest" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客户押汇利息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerNegotiatedInterest" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('资方延期利息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorNegotiatedYqInterest" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客户延期利息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerNegotiatedYqInterest" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('资方本息合计')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorTotalPrincipalInterest" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客户本息合计')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerTotalPrincipalInterest" class="form-control number" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('还汇信息-资方')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('实际还汇日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorActualRepaymentDate" readonly="true" maxlength="20" class="form-control"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('实际汇率')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorRealExchangeRate" maxlength="10" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('预估汇率')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorEstimatedExchangeRate" maxlength="10" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
<!--					<div class="col-xs-6">-->
<!--						<div class="form-group">-->
<!--							<label class="control-label col-sm-4" title="">-->
<!--								<span class="required hide">*</span> ${text('预估价格')}：<i class="fa icon-question hide"></i></label>-->
<!--							<div class="col-sm-8">-->
<!--								<#form:input path="investorEstimatedPrice" class="form-control number" readonly="true"/>-->
<!--							</div>-->
<!--						</div>-->
<!--					</div>-->
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('预付单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="prepaymentId"  items="${listPrepayment}" itemLabel="prepaymentCode"
								itemValue="prepaymentId" blankOption="true" class="form-control " readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('发生天数')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="investorActualDays" class="form-control digits" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('还汇应付单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="investorPayableId" items="${listAp}" itemLabel="apCode"
								itemValue="apId" class="form-control" readonly="true" blankOption="true" />
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('还汇信息-客户')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('实际还汇日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerActualRepaymentDate" readonly="true" maxlength="20" class="form-control"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('实际汇率')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerRealExchangeRate" maxlength="10" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('预估汇率')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerEstimatedExchangeRate" maxlength="10" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
<!--					<div class="col-xs-6">-->
<!--						<div class="form-group">-->
<!--							<label class="control-label col-sm-4" title="">-->
<!--								<span class="required hide">*</span> ${text('预估价格')}：<i class="fa icon-question hide"></i></label>-->
<!--							<div class="col-sm-8">-->
<!--								<#form:input path="customerEstimatedPrice" class="form-control number" readonly="true"/>-->
<!--							</div>-->
<!--						</div>-->
<!--					</div>-->
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('预收单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="advancesReceivedId"  items="${listAdvancesReceived}" itemLabel="advancesReceivedCode"
								itemValue="advancesReceivedId" blankOption="true" class="form-control " readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('发生天数')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerActualDays" class="form-control digits" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('还汇应收单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="customerReceivableId"  items="${listAr}" itemLabel="arCode" blankOption="true"
                                itemValue="arId" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('附件上传')}</h4>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('附件上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadFile" bizKey="${billNegotiated.id}" bizType="billNegotiated_file"
								uploadType="all" class="" readonly="false" preview="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('不符点说明')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('系统信息')}</h4>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建者')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="createBy" maxlength="64" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="createDate" readonly="true" maxlength="20" class="form-control "
								dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('更新者')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="updateBy" maxlength="64" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('更新时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="updateDate" readonly="true" maxlength="20" class="form-control"
								dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
				</div>

			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('financial:billnegotiated:billNegotiated:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
	function checkInvEndDate(){
		let startDate=$("#startDate").val();
		let endDate=$("#investorEndDate").val();
		if(endDate<=startDate){
			$("#endDate").val('');
			js.showErrorMessage("资方结束日期不能早于开始日期！");
		}
	}
	function checkCusEndDate(){
		let startDate=$("#startDate").val();
		let endDate=$("#customerEndDate").val();
		if(endDate<=startDate){
			$("#endDate").val('');
			js.showErrorMessage("客户结束日期不能早于开始日期！");
		}
	}
//初始化到单押汇明细DataGrid对象
$("#billNegotiatedDetailDataGrid1").dataGrid({
	data: ${toJson(billNegotiated.billNegotiatedDetailList1)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'类型', name:'type', editable:true, hidden:true},
		{header:'主键', name:'billNegotiatedDetailId', editable:true, hidden:true},
		{header:'${text("发生天数")}', name:'days', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits', 'readonly':'true'}},
		/*{header:'${text("押汇日期起")}', name:'startDate', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control', 'readonly':'true'}},
		{header:'${text("押汇日期至")}', name:'endDate', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		*/
		{header:'${text("押汇日期起")}', name:'startDate', width:150,
			formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:true, edittype:'text', editoptions:{'class':'form-control', 'readonly':'true',
				dataInit: function(element){
					laydate.render({elem:element, type:'date', format:'yyyy-MM-dd'});
				}
			}
		},
		{header:'${text("押汇日期至")}', name:'endDate', width:150,
			formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:true, edittype:'text', editoptions:{'class':'form-control', 'readonly':'true',
				dataInit: function(element){
					laydate.render({elem:element, type:'date', format:'yyyy-MM-dd'});
				}
			}
		},
		{header:'${text("资方-保证金比例")}', name:'marginRatio', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control', 'readonly':'true'}},
		{header:'${text("资方-保证金金额(RMB)")}', name:'marginAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		{header:'${text("资方-押汇利率")}', name:'negotiatedRate', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control', 'readonly':'true'}},
		// {header:'${text("资方-押汇利息")}', name:'negotiatedInterest', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		// {header:'${text("应还款金额")}', name:'repaymentAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		{header:'${text("备注")}', name:'remark', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control'}},
		{header:'${text("到单押汇ID")}', name:'billNegotiatedId.billNegotiatedId', editable:true, hidden:true},
		// {header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
		// 	var actions = [];
		// 	if (val == 'new'){
		// 		actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#billNegotiatedDetailDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
		// 	}else{
		// 		actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#billNegotiatedDetailDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
		// 	}
		// 	return actions.join('');
		// }, editoptions: {defaultValue: 'new'}}
	],

	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#billNegotiatedDetailDataGridAddRowBtn1'),	// 子表增行按钮
	editGridAddRowInitData: {billNegotiatedDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

	// 编辑表格的提交数据参数
	editGridInputFormListName: 'billNegotiatedDetailList1', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,billNegotiatedDetailId,days,startDate,endDate,marginRatio,marginAmount,negotiatedRate,negotiatedInterest,repaymentAmount,remark,type,billNegotiatedId.billNegotiatedId,', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
$("#billNegotiatedDetailDataGrid2").dataGrid({
	data: ${toJson(billNegotiated.billNegotiatedDetailList2)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'类型', name:'type', editable:true, hidden:true},
		{header:'主键', name:'billNegotiatedDetailId', editable:true, hidden:true},
		{header:'${text("发生天数")}', name:'days', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits', 'readonly':'true'}},
		/*{header:'${text("押汇日期起")}', name:'startDate', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control','readonly':'true'}},
		{header:'${text("押汇日期至")}', name:'endDate', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		*/
		{header:'${text("押汇日期起")}', name:'startDate', width:150,
			formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:true, edittype:'text', editoptions:{'class':'form-control', 'readonly':'true',
				dataInit: function(element){
					laydate.render({elem:element, type:'date', format:'yyyy-MM-dd'});
				}
			}
		},
		{header:'${text("押汇日期至")}', name:'endDate', width:150,
			formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:true, edittype:'text', editoptions:{'class':'form-control', 'readonly':'true',
				dataInit: function(element){
					laydate.render({elem:element, type:'date', format:'yyyy-MM-dd'});
				}
			}
		},
		{header:'${text("客户-保证金比例")}', name:'marginRatio', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control','readonly':'true'}},
		{header:'${text("客户-保证金金额")}', name:'marginAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		{header:'${text("客户-押汇利率")}', name:'negotiatedRate', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control','readonly':'true'}},
		// {header:'${text("客户-押汇利息")}', name:'negotiatedInterest', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		// {header:'${text("应还款金额")}', name:'repaymentAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		{header:'${text("备注")}', name:'remark', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control'}},
		{header:'${text("到单押汇ID")}', name:'billNegotiatedId.billNegotiatedId', editable:true, hidden:true},
		// {header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
		// 		var actions = [];
		// 		if (val == 'new'){
		// 			actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#billNegotiatedDetailDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
		// 		}else{
		// 			actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#billNegotiatedDetailDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
		// 		}
		// 		return actions.join('');
		// 	}, editoptions: {defaultValue: 'new'}}
	],

	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#billNegotiatedDetailDataGridAddRowBtn2'),	// 子表增行按钮
	editGridAddRowInitData: {billNegotiatedDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

	// 编辑表格的提交数据参数
	editGridInputFormListName: 'billNegotiatedDetailList2', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,billNegotiatedDetailId,days,startDate,endDate,marginRatio,marginAmount,negotiatedRate,negotiatedInterest,repaymentAmount,remark,type,billNegotiatedId.billNegotiatedId,', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
frameNumberChange();
function frameNumberChange() {
	if ($("#frameNumber").val()) {
		$.ajax({
			type: "POST",
			url: "${ctx}/financial/billnegotiated/billNegotiated/getCarInfo",
			data: {"frameNumber": $("#frameNumber").val()},
			success: function (data) {
				$("#brandName").val(data.brand).trigger('change');
				$("#areaName").val(data.area).trigger('change');
				$("#brand").attr("value", data.brand);
				$("#area").attr("value", data.area);
				$("#model").attr("value", data.model);
				$("#unitPrice").attr("value", data.unitPrice);
				$("#carId").attr("value", data.carId);
				$("#rowNumber").attr("value", data.rowNumber);
				$("#negotiatedAmount").attr("value", $("#unitPrice").val() * $("#negotiatedRatio").val() / 100);
			}
		});
		$.ajax({
			type : "post",
			async : false,
			url : "${ctx}/financial/billnegotiated/billNegotiated/getList",
			data : {
				'supplierId' : $("#investorId").val()
			},
			dataType : "json",
			success : function(msg) {
				$("#investorNegotiatedPlan").empty();
				if (msg.length > 0) {
					for (let i = 0; i < msg.length; i++) {
						let partId = msg[i].investorFinancialInfoId;
						let partName = msg[i].groupName;
						let option = $("<option>").attr({"value" : partId}).text(partName);
						$("#investorNegotiatedPlan").append(option);
					}
					$("#investorNegotiatedPlan option:first").prop("selected", 'selected');
					$("#investorNegotiatedPlan").change();
				}
			},
			error : function(json) {
				$.jBox.alert("网络异常！");
			}
		});
	} else {
		$("#brandName").val("").trigger('change');
		$("#areaName").val("").trigger('change');
		$("#model").attr("value", "");
		$("#unitPrice").attr("value", "");
		$("#negotiatedAmount").attr("value", "");
		$("#carId").attr("value", "");
		$("#brand").attr("value", "");
		$("#area").attr("value", "");
	}
	if (typeof window.webuploaderRefresh == 'function'){
		window.webuploaderRefresh();
	}
}

function startDateChange() {
	if ($("#startDate").val() != "") {
		$.ajax({
			type: "POST",
			url: "${ctx}/financial/billnegotiated/billNegotiated/getInvestorFinancialInfo",
			data: {
				"id" : $("#investorNegotiatedPlan").val()
				},
			success: function (data) {
				let ids1 = $('#billNegotiatedDetailDataGrid1').dataGrid('getDataIDs');
				for (let i = 0; i < ids1.length ; i++) {
					$('#billNegotiatedDetailDataGrid1').dataGrid('delRowData', ids1[i]);
				}
				for(let i=0; i<data.negotiatedInterestList1.length; i++){
					let days = 0;
					if($("#n1Flag").val() == "1"){
						days = data.negotiatedInterestList1[i].days + 1;
					} else {
						days = data.negotiatedInterestList1[i].days;
					}
					if(i==0) {

						$("#investorEndDate").attr("value", js.formatDate(js.addDate(js.parseDate($("#startDate").val()), data.negotiatedInterestList1[i].days), 'yyyy-MM-dd'));
						$("#investorInterestRatio").attr("value", data.negotiatedInterestList1[i].investorInterestRatio);
					} else {
						if(i == 1){
							$("#billNegotiatedDetailDataGrid1").jqGrid("addRow", {
								position: "last",
								addRowParams: {keys: false, focusField: true},
								initdata: {id: "", status: Global.STATUS_NORMAL, days:days,
									startDate:js.formatDate(js.addDate(js.parseDate($("#investorEndDate").val()), 1), 'yyyy-MM-dd').toString(),
									endDate:js.formatDate(js.addDate(js.parseDate($("#investorEndDate").val()), days), 'yyyy-MM-dd').toString(),
									marginRatio:data.negotiatedInterestList1[i].investorMarginRatio,
									negotiatedRate:data.negotiatedInterestList1[i].investorInterestRatio,
									type:1,
									marginAmount:$("#negotiatedAmount").val()*data.negotiatedInterestList1[i].investorMarginRatio /100 *$("#tentativeExchangeRate").val(),
								}
							});
						} else {
							//let rowid = 'jqg' + (i - 1)
							let rowlength=$('#billNegotiatedDetailDataGrid1').dataGrid('getDataIDs').length;
							let rowid=$('#billNegotiatedDetailDataGrid1').dataGrid('getDataIDs')[rowlength-1];

							$('#billNegotiatedDetailDataGrid1').dataGrid('saveRow', rowid, true);
							$("#billNegotiatedDetailDataGrid1").dataGrid("restoreRow", rowid);
							$("#billNegotiatedDetailDataGrid1").jqGrid("addRow", {
								position: "last",
								addRowParams: {keys: false, focusField: true},
								initdata: {id: "", status: Global.STATUS_NORMAL, days:days,
									startDate:js.formatDate(js.addDate(js.parseDate($('#billNegotiatedDetailDataGrid1').dataGrid('getRowData', rowid).endDate), 1), 'yyyy-MM-dd').toString(),
									endDate:js.formatDate(js.addDate(js.parseDate($('#billNegotiatedDetailDataGrid1').dataGrid('getRowData', rowid).endDate),days), 'yyyy-MM-dd').toString(),
									marginRatio:data.negotiatedInterestList1[i].investorMarginRatio,
									negotiatedRate:data.negotiatedInterestList1[i].investorInterestRatio,
									type:1,
									marginAmount:$("#negotiatedAmount").val()*data.negotiatedInterestList1[i].investorMarginRatio /100 *$("#tentativeExchangeRate").val(),
								}
							});
							$('#billNegotiatedDetailDataGrid1').dataGrid('editRow', rowid);
						}

					}
				}
				let ids2 = $('#billNegotiatedDetailDataGrid2').dataGrid('getDataIDs');
				for (let i = 0; i < ids2.length ; i++) {
					$('#billNegotiatedDetailDataGrid2').dataGrid('delRowData', ids2[i]);
				}
				for(let i=0; i<data.negotiatedInterestList2.length; i++){
					let days = 0;
					if($("#n1Flag").val() == "1"){
						days = data.negotiatedInterestList2[i].days + 1;
					} else {
						days = data.negotiatedInterestList2[i].days;
					}
					if(i==0) {

						$("#customerEndDate").attr("value", js.formatDate(js.addDate(js.parseDate($("#startDate").val()), data.negotiatedInterestList2[i].days), 'yyyy-MM-dd'));
						$("#customerInterestRatio").attr("value", data.negotiatedInterestList2[i].customerInterestRatio);
					} else {
						if(i == 1){
							$("#billNegotiatedDetailDataGrid2").jqGrid("addRow", {
								position: "last",
								addRowParams: {keys: false, focusField: true},
								initdata: {id: "", status: Global.STATUS_NORMAL, days,
									startDate:js.formatDate(js.addDate(js.parseDate($("#customerEndDate").val()), 1), 'yyyy-MM-dd').toString(),
									endDate:js.formatDate(js.addDate(js.parseDate($("#customerEndDate").val()), days), 'yyyy-MM-dd').toString(),
									marginRatio:data.negotiatedInterestList2[i].customerMarginRatio,
									negotiatedRate:data.negotiatedInterestList2[i].customerInterestRatio,
									type:2,
									marginAmount:$("#negotiatedAmount").val()*data.negotiatedInterestList2[i].customerMarginRatio /100 *$("#tentativeExchangeRate").val(),
								}
							});
						} else {
							//let rowid = 'jqg' + (i - 1);

							let rowlength2=$('#billNegotiatedDetailDataGrid2').dataGrid('getDataIDs').length;
							let rowid2=$('#billNegotiatedDetailDataGrid2').dataGrid('getDataIDs')[rowlength2-1];
							$('#billNegotiatedDetailDataGrid2').dataGrid('saveRow', rowid2, true);
                        $("#billNegotiatedDetailDataGrid2").dataGrid("restoreRow", rowid2);

							$("#billNegotiatedDetailDataGrid2").jqGrid("addRow", {
								position: "last",
								addRowParams: {keys: false, focusField: true},
								initdata: {id: "", status: Global.STATUS_NORMAL, days:days,
									startDate:js.formatDate(js.addDate(js.parseDate($('#billNegotiatedDetailDataGrid2').dataGrid('getRowData', rowid2).endDate), 1), 'yyyy-MM-dd').toString(),
									endDate:js.formatDate(js.addDate(js.parseDate($('#billNegotiatedDetailDataGrid2').dataGrid('getRowData', rowid2).endDate), days), 'yyyy-MM-dd').toString(),
									marginRatio:data.negotiatedInterestList2[i].customerMarginRatio,
									negotiatedRate:data.negotiatedInterestList2[i].customerInterestRatio,
									type:2,
									marginAmount:$("#negotiatedAmount").val()*data.negotiatedInterestList2[i].customerMarginRatio /100 *$("#tentativeExchangeRate").val(),
								}
							});
							$('#billNegotiatedDetailDataGrid2').dataGrid('editRow', rowid2);
						}

					}
				}
				if (typeof window.webuploaderRefresh == 'function'){
					window.webuploaderRefresh();
				}
			}
		});
	} else {

	}

}

function n1FlagChange(){
	startDateChange();
	if (typeof window.webuploaderRefresh == 'function'){
		window.webuploaderRefresh();
	}
}

</script>
